# GDIR define
GDIR=../../../../..


# MACIPATH define
MACIPATH=$(GDIR)/MaCI


# External includes
include $(GDIR)/GIMI/Makefile.gimi
include $(MACIPATH)/interfaces/MaCI-interfaces.Makefile


# params
CC=gcc
CXX=g++
EXTRADEFS=-DLINUX_OS -DGIMI_NO_DATATYPE_INCLUDES $(CE)
MACIPATH=$(GDIR)/MaCI
UTILSPATH=$(GDIR)/utils
BUSPATH=$(MACIPATH)/bus
DRIVERPATH=$(MACIPATH)/drivers
MACIINTERFACEPATH=$(MACIPATH)/interfaces
INCLUDES=-I$(UTILSPATH) $(INCGIMI) \
	-I$(BUSPATH)/ASRoboBus \
	-I$(BUSPATH)/ASRobo_serial \
	-I$(BUSPATH)/ASRobo_ioport \
	-I$(DRIVERPATH)/Ranging/SICK \
	-I$(DRIVERPATH)/Ranging/URGLaser \
	-I$(DRIVERPATH)/Motor/ESC629 \
	-I$(DRIVERPATH)/Avant/ \
	-I$(BUSPATH)/ASRobo_can/include \
	-I$(BUSPATH)/ASRobo_can \
	$(MACI_INCLUDE_PATHS)
WFLAGSC=-Wall -Wunused -Wshadow
WFLAGSCPP=-Wall -Wunused -Wshadow -Weffc++
WFLAGSDCPP=
CFLAGS=-O0 -g3 $(WFLAGSC) $(INCLUDES) $(EXTRADEFS)
CPPFLAGS=-O0 -g3 $(WFLAGSCPP) $(INCLUDES) $(EXTRADEFS)
DCPPFLAGS=-O0 -g3 $(WFLAGSDCPP) $(INCLUDES) $(EXTRADEFS)
LD=g++
LDFLAGS=
LIBS=$(MACI_EXT_LIBRARIES) -lrt -lpthread $(LIBSGIMI) 

SRCSC=$(CGIMI) $(MACI_INTERFACE_IMAGE_EXT_C)
SRCSCPP=$(CPPGIMI)
MACISRCSCPP=$(MACI_EXT_SRC_CPP) \
	    $(MACI_BASE_SRC_CPP) \
	    $(MACI_INTERFACE_JOINTGROUPCTRL_COMMON_CPP) \
	    $(MACI_INTERFACE_JOINTGROUPCTRLCLIENT_CPP) \
	    $(MACI_INTERFACE_TEXT_COMMON_CPP) \
	    $(MACI_INTERFACE_TEXTCLIENT_CPP) \
	    $(MACI_INTERFACE_IMAGE_COMMON_CPP) \
	    $(MACI_INTERFACE_IMAGECLIENT_CPP) \
	    $(MACI_INTERFACE_IMAGE_EXT_CPP) \
	    $(MACI_INTERFACE_POSITION_COMMON_CPP) \
	    $(MACI_INTERFACE_POSITIONCLIENT_CPP) \
	    $(MACI_INTERFACE_RANGING_COMMON_CPP) \
	    $(MACI_INTERFACE_RANGINGCLIENT_CPP) \
	    $(MACI_INTERFACE_SPEEDCTRL_COMMON_CPP) \
	    $(MACI_INTERFACE_SPEEDCTRLCLIENT_CPP) \
			$(MACI_INTERFACE_COORDINATEDRIVE_COMMON_CPP) \
	    $(MACI_INTERFACE_COORDINATEDRIVECLIENT_CPP) \
	    $(MACI_INTERFACE_MAP_COMMON_CPP) \
	    $(MACI_INTERFACE_MAPCLIENT_CPP) \
	    $(UTILSPATH)/PNGLiteInterface.opp
	    
VPATH=

# Construct final lists of CPP and C objects
OBJSC=$(SRCSC:.c=.o)
OBJSCPP=$(SRCSCPP:.cpp=.opp)
MACIOBJSCPP=$(MACISRCSCPP:.cpp=.opp)

# Define COMPILE and LINK commands
COMPILEC=$(CC) $(CFLAGS) -c
COMPILECPP=$(CXX) $(CPPFLAGS) -c
COMPILEDCPP=$(CXX) $(DCPPFLAGS) -c
LINK=$(LD) $(LDFLAGS) 

.PHONY: all

# Define targets
TARGETS=3MUI

# All rule compiles all per default
all:	$(TARGETS)

###############################################
###############################################
########### SpeedCtrl DUMMY module ############
3MUI: $(OBJSC) $(OBJSCPP) $(MACIOBJSCPP) \
	  3MUI-app.opp
	@$(LINK) -o $@ $^ $(LIBS) 
	@echo "      [LD] $@"
###############################################

###############################################
###############################################
.PHONY: clean maci-clean maciclean real-clean realclean
local-clean clean:
	@rm -f *.o *.opp $(TARGETS)
	@echo "     [LOCAL-CLEAN]"

maci-clean maciclean: clean
	rm -f $(MACIOBJSCPP)
	@echo "     [MACI-CLEAN]"

real-clean realclean: maciclean
	rm -f $(OBJSC) $(OBJSCPP)
	@echo "     [REAL-CLEAN]"

########### Compile rules ####################
# Compile rule for all .o (.c) file
%.o:	%.c
	@$(COMPILEC) -o $@ $<
	@echo "      [CC] $<"

# Compile rule for all .opp (.cpp) files
%.opp:	%.cpp
	@$(COMPILECPP) -o $@ $<
	@echo "      [CXX] $<"

# Compile rule for all .dopp (dirty .cpp) files
%.dopp:	%.cpp
	@$(COMPILEDCPP) -o $@ $<
	@echo "      [DIRTY-CXX] $<"

##############################################
